  var totalPage =2;//一共多少页数据
  var pageSize =10;//每页显示10条数据
  var currentPage =1;//当前第几页数据，默认为1
  var isLoading = false;//是否正在加载更多数据//
$(function(){
	query(1);
	var option={};
	function query(pageNum){    
		var myChart = echarts.init(document.getElementById('main-chart'));
		var p={};
		p.pageSize=pageSize;
		 p.pageNum = pageNum;
		 var orderNameList = new Array();
         var orderQuantity = new Array();
		/* $('#totalOrder-table').empty();
		 $('#totalOrder-table').append('<tr><td  hidden="true">主键号</td> <td>序号</td> <td>订单名称</td><td>总数量</td><td>总价</td></tr>');*/
			$.ajax({
				  type:"POST",
				  url:"/movie.front/orderController/getTotalTicketList",
				  data:JSON.stringify(p),
				  dataType:"json",
				  contentType:"application/json",
				  success:function(data){
		           array = data.result.list;
		           for(var i=0;i<array.length;i++){
		        	   orderNameList[i] = array[i].orderName;
		               orderQuantity[i] = array[i].totalQuantity
		           }
				   //总共多少页
		           $('#paginator').empty();
		           var totalPages = data.result.pages;
		        	   var pageHtml = '<ul>';
		        	   pageHtml =pageHtml+'<li class="m-pagination-page"><a herf="javascript:void(0);" id="firstPage" onclick="firstPagesquery(1)"> 首页 </a></li>';
		        	   for(var i=0;i<totalPages;i++){
		        		  pageHtml = pageHtml+'<li class="m-pagination-page"><a herf="javascript:void(0);" onclick="currentPagesquery('+(i+1)+')" id='+(i+1)+'>'+(i+1)+'</a></li>'; 
		        	   }
		        	   pageHtml =pageHtml+'<li class="m-pagination-page"><a herf="javascript:void(0);" id="endPage" onclick="endPagequery('+totalPages+')">尾页</a></li>';
		        	   pageHtml =pageHtml+'</ul>';
		        	   $('#paginator').append(pageHtml);
		       		/*alert(orderNameList);
					alert(orderQuantity);*/
					 option = {
					            title: {
					                text: '票房分析'
					            },
					            tooltip: {},
					            legend: {
					                data:['销量']
					            },
					            xAxis: {
					                data: orderNameList
					            },
					            yAxis: {},
					            series: [{
					                name: '销量',
					                type: 'bar',
					                data:orderQuantity
					            }]
					        };
					 myChart.setOption(option);
				  }
			
			   });
	
			
			
	}
	
	$('#btn-search').click(function(){
		startTime =  $('#search-startTime')[0].value;
		endTime = $('#search-endTime')[0].value;
		querySearch(1,startTime,endTime);
	});
	$('#btn-reset').click(function(){
		$('#search-startTime').val('');
		$('#search-endTime').val('');
	});
	
	function querySearch(pageNum,startTime,endTime){
		$('#main-chart').empty();
		var myChart = echarts.init(document.getElementById('main-chart'));
		var p={};
		p.pageSize=pageSize;
		 p.pageNum = pageNum;
		 p.startTime = startTime;
		 p.endTime = endTime;
		 var orderNameList = new Array();
         var orderQuantity = new Array();
		/* $('#totalOrder-table').empty();
		 $('#totalOrder-table').append('<tr><td  hidden="true">主键号</td> <td>序号</td> <td>订单名称</td><td>总数量</td><td>总价</td></tr>');*/
			$.ajax({
				  type:"POST",
				  url:"/movie.front/orderController/getTotalTicketList",
				  data:JSON.stringify(p),
				  dataType:"json",
				  contentType:"application/json",
				  success:function(data){
		           array = data.result.list;
		           for(var i=0;i<array.length;i++){
		        	   orderNameList[i] = array[i].orderName;
		               orderQuantity[i] = array[i].totalQuantity
		           }
				   //总共多少页
		           $('#paginator').empty();
		           var totalPages = data.result.pages;
		        	   var pageHtml = '<ul>';
		        	   pageHtml =pageHtml+'<li class="m-pagination-page"><a herf="javascript:void(0);" id="firstPage" onclick="firstPagesquery(1)"> 首页 </a></li>';
		        	   for(var i=0;i<totalPages;i++){
		        		  pageHtml = pageHtml+'<li class="m-pagination-page"><a herf="javascript:void(0);" onclick="currentPagesquery('+(i+1)+')" id='+(i+1)+'>'+(i+1)+'</a></li>'; 
		        	   }
		        	   pageHtml =pageHtml+'<li class="m-pagination-page"><a herf="javascript:void(0);" id="endPage" onclick="endPagequery('+totalPages+')">尾页</a></li>';
		        	   pageHtml =pageHtml+'</ul>';
		        	   $('#paginator').append(pageHtml);
		       		/*alert(orderNameList);
					alert(orderQuantity);*/
					 option = {
					            title: {
					                text: '票房分析'
					            },
					            tooltip: {},
					            legend: {
					                data:['销量']
					            },
					            xAxis: {
					                data: orderNameList
					            },
					            yAxis: {},
					            series: [{
					                name: '销量',
					                type: 'bar',
					                data:orderQuantity
					            }]
					        };
					 myChart.setOption(option);
				  }
			
			   });
		
	}
    $('#search-startTime').datetimepicker({
        minView:'year',
	    lang:'ch',
	    timepicker:true,
	   // format:'Y-m-d H:i:s',
	    format:'Y-m-d H:i:00',
	    allowBlank: true,
	    
	}); 
    $('#search-endTime').datetimepicker({
        minView:'year',
	    lang:'ch',
	    timepicker:true,
	   // format:'Y-m-d H:i:s',
	    format:'Y-m-d H:i:00',
	    allowBlank: true,
	    
	}); 
    
});

//当前页
function currentPagesquery(currentId){
	 // alert(currentId);当前页码
	$('#main-chart').empty();
	var myChart = echarts.init(document.getElementById('main-chart'));
	  $('#paginator').empty();
	     var p ={};
         p.pageSize =10;
         p.pageNum = currentId;
		 var orderNameList = new Array();
         var orderQuantity = new Array();
			$.ajax({
				  type:"POST",
				  url:"/movie.front/orderController/getTotalTicketList",
				  data:JSON.stringify(p),
				  dataType:"json",
				  contentType:"application/json",
				  success:function(data){
		           array = data.result.list;
		           for(var i=0;i<array.length;i++){
		        	   orderNameList[i] = array[i].orderName;
		               orderQuantity[i] = array[i].totalQuantity
		           }
				   //总共多少页
		           $('#paginator').empty();
		           var totalPages = data.result.pages;
		        	   var pageHtml = '<ul>';
		        	   pageHtml =pageHtml+'<li class="m-pagination-page"><a herf="javascript:void(0);" id="firstPage" onclick="firstPagesquery(1)"> 首页 </a></li>';
		        	   for(var i=0;i<totalPages;i++){
		        		  pageHtml = pageHtml+'<li class="m-pagination-page"><a herf="javascript:void(0);" onclick="currentPagesquery('+(i+1)+')" id='+(i+1)+'>'+(i+1)+'</a></li>'; 
		        	   }
		        	   pageHtml =pageHtml+'<li class="m-pagination-page"><a herf="javascript:void(0);" id="endPage" onclick="endPagequery('+totalPages+')">尾页</a></li>';
		        	   pageHtml =pageHtml+'</ul>';
		        	   $('#paginator').append(pageHtml);
		       		/*alert(orderNameList);
					alert(orderQuantity);*/
					 option = {
					            title: {
					                text: 'ECharts 入门示例'
					            },
					            tooltip: {},
					            legend: {
					                data:['销量']
					            },
					            xAxis: {
					                data: orderNameList
					            },
					            yAxis: {},
					            series: [{
					                name: '销量',
					                type: 'bar',
					                data:orderQuantity
					            }]
					        };
					 myChart.setOption(option);
				  }
			
			   });
	
}

//首页
function  firstPagesquery(firstPageId){
	currentPagesquery(firstPageId);
}

//尾页
function  endPagequery(endPageId){
	currentPagesquery(endPageId);
	 }
